package turrets;
import Enemies.Enemy;
import Manage.Counter;
import info.gridworld.actor.Actor;
import info.gridworld.grid.Location;
import Generator.*;
import java.util.ArrayList;
public class Obstruction extends Actor{
	protected static int price = 100;
	private int damage, life;
	public Obstruction(int dam, int lif){
		super();
		life = lif;
		damage = dam;
		Counter.addMoney(-1*getPrice());
	}
	public Obstruction(){
		life = 5;
		damage = 5;
		Counter.addMoney(-1*getPrice());
	}
	public static int getPrice(){
		return price;
	}
	public int getLife(){
		return life;
	}
	public void reduceLife(){
		life--;
	}
	public void act(){
		ArrayList<Enemy> enemies = getEnemy();
		if(enemies.size() !=0){
			for(int x = 0;x<enemies.size();x++){	
				enemies.get(x).takeDamage(damage);
				reduceLife();
				if(life == 0){
					Location loc = new Location(getLocation().getRow(),getLocation().getCol(),0);
					Path b = new Path();
					this.removeSelfFromGrid(loc);
					b.putSelfInGrid(getGrid(), loc);
					break;
				}
			}
		}
	}
	public ArrayList<Enemy> getEnemy(){
		ArrayList<Enemy> enemies = new ArrayList<Enemy>();
		int r = getLocation().getRow();
		int c = getLocation().getCol();
		for(int x = 0;x<getGrid().getNumDep();x++){
			if(getGrid().get(new Location(r,c,x)) instanceof Enemy)
				enemies.add((Enemy) getGrid().get(new Location(r,c,x)));
		}
		return enemies;
	}
}
